import http from '@/utils/request.js'

export default {
    // 商品图片上传接口，接收 File 类型的文件
    uploadAvatar: (file) => { // 参数改为直接接收 File 对象（用户选择的图片）
        const formData = new FormData(); // 关键：用 FormData 封装参数
        formData.append('file', file); // 关键：参数名必须是 'file'，与后端 @RequestParam("file") 对应

        return http({
            url: '/api/product/avatar', // 注意：后端接口是 /api/admin/avatar，确保URL与后端一致
            method: 'post',
            data: formData, // 传递 FormData 对象
        });
    },
    addProduct: (obj) => {
        return http({
            url: '/api/product/add',
            method: 'post',
            data: obj
        });
    },
    editProduct: (obj) => {
        return http({
            url: '/api/product/update',
            method: 'put',
            data: obj
        });
    },
    getProducts: (obj) => {
        return http({
            url: '/api/product/getProducts',
            method: 'get',
            params: obj
        });
    },
    updateStatus: (obj) => {
        return http({
            url: `/api/product/updateStatus`,
            method: 'put',
            data: obj
        });
    },
    ProductSimpleList: () => {
        return http({
            url: '/api/product/getSimpleProduct',
            method: 'get'
        });
    },
    getProductInfo: (id) => {
        return http({
            url: `/api/product/get/${id}`,  //拼接id要用反引号
            method: 'get'
        });
    },
    getStore: (id) => {
        return http({
            url: `/api/product/getStore/${id}`,
            method: 'get'
        });
    },
    getSimpleProducts: (obj) => {
        return http({
            url: '/api/product/getSimpleProducts',
            method: 'get',
            params: obj
        });
    },
    updateStore: (obj) => {
        return http({
            url: '/api/product/updateStore',
            method: 'put',
            data: obj
        });
    },
}